<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>展开运算符的使用</title>
</head>
<body>
    <script>
        let arr1 = [1,2,3]
        let arr2 = [4,5,6]
        console.log(...arr1); // 展开运算符
        console.log([...arr1,...arr2]); // 展开合并
        function sum(...num) { // 展开求和  num为数组[1,2,3,4]
            return  num.reduce((pre,cur)=>{  // reduce方法  
                return pre+cur
            })
        }
        console.log(sum(1,2,3,4));
        let person1 = {name:'tom',age:18}
        // let person2 = person1  // 复制  直接把person1拷贝过来  person1改变 person2跟着变化
        // person1.name = 'jerry'
        // console.log(person2);
        // console.log(...person); // 对象不能解构
        let person2 = {...person1} // 构建字面量对象时使用展开语法
        person1.name ='jerry'
        console.log(person1); // person1改变  person2不变
        console.log(person2);
        let person3 = {...person1,name:'jack',address:'China'}
        console.log(person3); // 合并
    </script>
</body>
</html>